#include <iostream>

using namespace std;

const int N = 1e5 + 10;

typedef long long LL;

LL m[N], r[N];
int n;

void exgcd(LL a, LL b, LL& x, LL& y)
{
	if(b == 0)
	{
		x = 1; y = 0;
		return;
	}
	LL x1, y1;
	exgcd(b, a % b, x1, y1);
	x = y1; y = x1 - a / b * y1;
	return;
}

LL qmul(LL a, LL b, LL p)
{
	LL ret = 0;
	while(b)
	{
		if(b & 1) ret = (ret + a) % p;
		b >>= 1;
		a = (a + a) % p; 
	}
	return ret;
}

LL crt()
{
	LL M = 1;
	for(int i = 1; i <= n; i++) M *= m[i];
	
	LL ret = 0;
	
	for(int i = 1; i <= n; i++)
	{
		LL c = M / m[i];
		LL x, y;
		exgcd(c, m[i], x, y);
		x = (x % m[i] + m[i]) % m[i];
		// c x r[i]
		ret = (ret + qmul(qmul(c, x, M), r[i], M)) % M;
	}
	return ret;
	
}

int main()
{
	
//	cout << qmul(5, 100, 1000000) << endl;
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> m[i] >> r[i];
	
	LL ans = crt();
	
	cout << ans << endl;
	return 0;
}
